/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.hpvas.gui.internalframe;

import edu.hpvas.control.SearchController;
import java.util.ArrayList;
import java.util.HashMap;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author raider
 */
public class IFSearch extends javax.swing.JInternalFrame {

    public IFSearch(String searchType,String words) {
        initComponents();
        setModelTSearchResults(searchType, words);
    }
    
    private void setModelTSearchResults(String searchType,String words){
        ArrayList<String[]>results=new SearchController().getSearchResults(searchType, words);
        String[] titles=results.get(0);
        String[][]data=new String[results.size()-1][titles.length];
        for (int i = 1; i < results.size(); i++) {
            data[i-1]=results.get(i);
        }
        TSearchResults.setModel(new DefaultTableModel(data,titles));
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        LSearchResults = new javax.swing.JLabel();
        SPSearchResults = new javax.swing.JScrollPane();
        TSearchResults = new javax.swing.JTable();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Search results");
        getContentPane().setLayout(new java.awt.BorderLayout(20, 20));
        getContentPane().add(LSearchResults, java.awt.BorderLayout.SOUTH);

        TSearchResults.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        TSearchResults.setEnabled(false);
        SPSearchResults.setViewportView(TSearchResults);

        getContentPane().add(SPSearchResults, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel LSearchResults;
    private javax.swing.JScrollPane SPSearchResults;
    private javax.swing.JTable TSearchResults;
    // End of variables declaration//GEN-END:variables
}
